using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ltf.Remoting.TeamFoundation;
using Lizard.Remoting.Settings;
using Ltf.Remoting.Settings;
using System.IO;

namespace Ltf.MonitorLizard.Controls
{
	public partial class ServerSelector : ComboBox
	{
		private TFServerConnection connection;

		public TFServerConnection Connection
		{
			get { return connection; }
			set 
			{
				connection = value;
				if (connection!=null)
					this.SelectedItem = value.Settings.Server;
			}
		}
	
		public ServerSelector()
		{
			InitializeComponent();
			this.DropDownStyle = ComboBoxStyle.DropDownList;
			if (ServerConnections.DefaultConnection != null && ServerConnections.DefaultConnection.Settings != null)
			{
				this.Items.Clear();
				this.Items.Add(ServerConnections.DefaultConnection.Settings.Server);
				foreach (TFSecondarySettings ss in ServerConnections.DefaultConnection.Settings.AlternativeServerSettings)
				{
					if (Directory.Exists(ss.DefaultWorkingPath))
						this.Items.Add(ss.Server);
				}
				this.SelectedIndex = 0;
			}
			
		}

		protected override void OnPaint(PaintEventArgs pe)
		{
			// TODO: Add custom paint code here

			// Calling the base class OnPaint
			base.OnPaint(pe);
		}

		protected override void OnSelectedIndexChanged(EventArgs e)
		{
			Connection = ServerConnections.GetConnectionByName(this.SelectedItem.ToString());
			base.OnSelectedIndexChanged(e);
		}
	}
}
